package org.jeecg.modules.interview.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.interview.entity.Interview;
import org.jeecg.modules.interview.mapper.InterviewMapper;
import org.jeecg.modules.interview.service.InterviewService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liujiamiao
 * @since 2020-11-04
 */
@Service
public class InterviewServiceImpl extends ServiceImpl<InterviewMapper, Interview> implements InterviewService {

    /**
     * 根据基本信息id获取面试情况信息
     * @param basicId
     * @return
     */
    @Override
    public Interview info(Integer basicId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("basic_id",basicId);
        Interview interview = baseMapper.selectOne(wrapper);
        return interview;
    }

    /**
     * 更新 或保存
     * @param interview
     */
    @Override
    public void saveOrUpdateEntity(Interview interview) {
        Interview info = this.info(interview.getBasicId());
        if(info!=null){
            //根据id修改，而resume为null也会保存，而不是忽略
            UpdateWrapper wrapper = new UpdateWrapper();
            wrapper.set("resume",interview.getResume());
            wrapper.eq("id",interview.getId());
            this.update(interview,wrapper);
        }else {
            this.save(interview);
        }
    }

}
